﻿@{
    ViewBag.Title = "内容管理";
    Layout = "~/Views/Shared/_ViewFormPage.cshtml";
}
@model ArticleVM
@section head{

    <script charset="utf-8" src="/Scripts/kindeditor-4.1.3/kindeditor-all-min.js?@CommonSetting.JsVersion"></script>
    <script charset="utf-8" src="/Scripts/kindeditor-4.1.3/lang/zh_CN.js?@CommonSetting.JsVersion"></script>
    <script src="/Scripts/AjaxFileUploaderV2.1/ajaxfileupload.js"></script>
    <script type="text/javascript">
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="Content"]', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: true,
                allowFileManager: false,
                syncType: 'form',
                width: '800px',
                height: '240px',
                uploadJson: '@Url.Action("Upload", "File")'
            });
        });

        function save() {
            if ($("#editForm").valid()) {
                editor.sync("Content");
                $('#editForm').ajaxSubmit({
                    beforeSubmit: function () {
                        $("#btnSave").off("click", save);
                    },
                    success: function (callback) {
                        if (callback) {
                            $.ligerDialog.success('保存成功', function (yes) {
                                self.location.href = "/Content/Edit";
                            });
                        }
                        else {
                            $.ligerDialog.error('保存失败');
                            $("#btnSave").on("click", save);
                        }
                    },
                    error: function (ex) {
                        $.ligerDialog.error('保存失败');
                        $("#btnSave").on("click", save);
                    }

                });
            }
        }


        $(function () {
            $("#btnSave").on("click", save);


            $("#btnUpload").click(function (e) {
                e.preventDefault();
                ajaxFileUpload();
            });



            $("#partitionFloor").change(function () {
                loadPartition($("#partitionParent"), $(this).val());
            });

            $("#partitionParent").change(function () {
                loadPartition($("#PartitionId"), $(this).val());
            });


        });

        function ajaxFileUpload() {
            var dialog = $.ligerDialog.waitting('正在上传,请稍候...');
            $.ajaxFileUpload({
                url: '/File/Upload',
                secureuri: false,
                fileElementId: 'imgFile',
                dataType: 'json',
                cache: false,
                data: { dir: 'image', localUrl: '' },
                success: function (data, status) {
                    if (typeof (data.error) !== 'undefined') {
                        if (data.error === 0) {
                            $("#productImage").attr("src", data.url);
                            $("#ImgUrl").val(data.url);
                        } else {
                            $.ligerDialog.error('上传出错' + message);
                        }
                    }
                },
                error: function (data, status, e) {
                    $.ligerDialog.error('上传出错' + e);
                }
                ,
                complete: function (XMLHttpRequest, textStatus) {
                    dialog.close();
                }
            })
            return false;
        }
    </script>
    @if (false)
    {
        <script src="../../Scripts/jquery-1.8.2.js"></script>
    }
    <style type="text/css">
    </style>
}
<div id="header" class="header">
    <h4>内容管理 -- 维护</h4>
</div>
@using (Html.BeginForm("Edit", "Content", FormMethod.Post, new { id = "editForm" }))
{
    @Html.HiddenFor(model => model.CompanyID)
    @Html.HiddenFor(model => model.ContentId)
    <div id="detail_forms">
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                标题
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.Title, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
                *
            </div>
        </div>
        @{
    var par = ViewBag.Partition as string;
    if (!string.IsNullOrEmpty(par) && par.StartsWith("HSZZ"))
    { 
            <div class="formsItems clearfix">
                <div class="formItem labelItem">
                    期数
                </div>
                <div class="formItem textItem">
                    @Html.TextBoxFor(model => model.Numbers, new { @class = "texts" })
                </div>
                <div class="formItem msgItem">
                </div>
            </div>
    }
        }



        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                图片
            </div>
            <div class="formItem textItem">
                <table border="0">
                    <tr>
                        <td style="height: 40px;">
                            <input type="file" id="imgFile" name="imgFile" />
                            <span class="buttons">
                                <a href="javascript:void(0);" id="btnUpload">上传</a>
                            </span>
                            <span>
                                @ViewBag.Size
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="showImage">
                                <img src='@Model.ImgUrl'  style="height:120px; cursor:pointer; width:200px;" alt="点击上传" title="点击上传" id="productImage" />
                            </div>
                        </td>
                        <td style="vertical-align: bottom;">
                            <div style="width: 220px; margin-left: 10px; display: block">

                                @Html.HiddenFor(m => m.ImgUrl)
                            </div>
                        </td>
                    </tr>
                </table>
                @Html.HiddenFor(model => model.ImgUrl)
            </div>
            <div class="formItem msgItem">
            </div>
        </div>

        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                描述
            </div>
            <div class="formItem textItem">
                @Html.TextAreaFor(model => model.Content, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
            </div>
        </div>



        <div id="btnContainer" class="formsItems">
            <div class="formItem labelItem">
                &nbsp;
            </div>
            <div class="formItem textItem">
                <a href="javascript:void(0);" id="btnSave">保存</a>
                <a href="Index?articlePartitionId = @ViewBag.Partition" id="btnCancel">取消</a>
            </div>
            <div class="formItem">
            </div>
        </div>
        <div class="formsItems"></div>
    </div>
}


